﻿using System.Threading.Tasks;

namespace Sidvall.Web.IO
{
    public class ServiceManager : IServiceManager
    {
        #region Public Members

        public StoreCollection Stores { get; set; }
        public Sidvall.Security.AuthorizationManager AuthorizationManager { get; set; }

        #region InitializeAsync

        public async Task InitializeAsync(string context)
        {
            var serviceManagerContext = Sidvall.Serialization.SerializerManager.Current.Deserialize<ServiceManagerContext>(context);
            this.Stores = serviceManagerContext.Stores;
            await this.Stores.InitializeAsync().ConfigureAwait(false);
            this.AuthorizationManager = await Sidvall.Security.SecurityManager.CreateAuthorizationManagerAsync(serviceManagerContext.AuthorizationProviderFactory,
                serviceManagerContext.AuthorizationProviderFactoryContext).ConfigureAwait(false);
        }

        #endregion

        #endregion
    }
}
